<template>
  <div class="goodsList">
    <div class="goodsChoose">
      <div
        class="choose"
        v-for="c in goodsList[0]?.children?.slice(0, 8)"
        :key="c.categoryId"
        @click="
          $router.push({ path: '/goods', query: { categoryId: c.categoryId } })
        "
      >
        <img :src="c.categoryImage" alt="" />
        <span>
          {{ c.categoryName }}
        </span>
      </div>
    </div>
    <ul class="list">
      <li
        v-for="item in goodsList[0]?.goodsList"
        :key="item.goodsId"
        @click="
          $router.push({
            path: '/product',
            query: { goodsId: item.goodsId, productId: item.defaultProductId },
          })
        "
      >
        <div class="msg">
          <img :src="item.goodsImage" alt="" />

          <p>{{ item.goodsName }}</p>
        </div>
        <div class="price">
          <span>￥{{ item.goodsPrice.toFixed(2) }}</span>
          <img
            src=" https://image-mall.gxptkc.com/m/resources/add-cart.png"
            alt=""
          />
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  data() {
    return {};
  },
  computed: {
    ...mapState(["goodsList"]),
  },
};
</script>
<style lang="scss" scoped>
.goodsList {
  padding: 8rem 0;
  background-color: rgb(245, 245, 245);
  width: 100%;
  .goodsChoose {
    margin: 10rem;
    border-radius: 10rem;
    width: calc(100vw - 20rem);
    box-sizing: border-box;
    background-color: #fff;
    display: flex;
    flex-wrap: wrap;
    // justify-content: space-between;
    .choose {
      width: 20%;
      border-radius: 10rem;
      border-radius: 5rem;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      padding: 8rem;
      margin-bottom: 8rem;
      > img {
        width: 53rem;
        height: 53rem;
        border-radius: 50%;
      }
      span {
        color: #333;
        margin-top: 10rem;
      }
    }
  }

  ul.list {
    padding: 0 8rem;
    display: flex;
    justify-content: left;
    flex-wrap: wrap;
    // background-color: #eee;
    li {
      background-color: #fff;
      padding-bottom: 10rem;
      margin-bottom: 10rem;
      width: 48%;
      height: 280rem;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      box-sizing: border-box;
      border-radius: 10rem;
      overflow: hidden;
      &:nth-child(2n) {
        margin-left: 14rem;
      }
      .msg {
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        > img {
          width: 100%;
        }
        > p {
          margin-top: 10rem;
          padding: 0 10rem 0 10rem;
          font-size: 14rem;

          width: 90%;
          display: -webkit-box;
          overflow: hidden;
          text-overflow: ellipsis;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
        }
      }
      .price {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 10rem 0 10rem;
        box-sizing: border-box;
        span {
          font-size: 17rem;
          color: rgb(252, 28, 28);
        }
        img {
          width: 21rem;
        }
      }
    }
  }
}
</style>